mui.plusReady(function () {
	var user = app.getState();
	var uid = user.user_id;
	var myWallet = ethscan.getWallet('eth');
	var self = plus.webview.currentWebview();
	var type = self.type;
	//console.log(type);
	mui.init({
		pullRefresh: {
			container: '#pullrefresh',
			up: {
				contentrefresh: '',
				callback: pullupRefresh
			}
		}
	});

	/**
	 * 上拉加载具体业务实现
	 */
	var count = 0;
	var p = 0;

	function pullupRefresh() {
		mui('#pullrefresh').pullRefresh().endPullupToRefresh((count++ > 100));
		var size = 20;
		var url = appurl + 'BuyApi/index';
		var postdata = {
			uid: uid,
			top: p,
			bottom: size
		};
		console.log(JSON.stringify(postdata));
		mui.post(url, postdata, function (res) {
			//console.log(JSON.stringify(res));
			if (res.data && res.data.length > 0) {
				p = p + res.data.length;
				document.getElementById('area').innerHTML = document.getElementById('area').innerHTML + template("tpl", {
					data: res.data
				});
			} else {
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
			}
		});
	}
	mui("#area").on('tap', '.table-span-go', function () {
		mui.alert(this.id + "完成");
		return;

		var postdata = {
			uid: uid,
			id: this.id
		};
		var me = this;
		var id = this.id;
		plus.nativeUI.showWaiting("验证中...");
		mui.post(serverurl + 'api/buy/verifHash', postdata, function (res) {
			console.log(JSON.stringify(res));
			plus.nativeUI.closeWaiting();

			if (res && res.error == 1) {
				//var el = document.querySelector("#" + id);
				//el.classList.remove('table-span-go');
				var datatype = me.getAttribute('data-type');
				if (datatype == 3) {
					//el.classList.addClass('table-span-cp');
					me.setAttribute('class', 'table-span-cp');
					me.innerHTML = '请求出票';
				} else {
					me.setAttribute('class', 'table-span-co');
					me.innerHTML = '交易完成';
				}
				//me.parentNode.removeChild(me);
				mui.alert(res.msg);
			} else {
				mui.alert('校验失败！');
			}
		});
	});
	mui("#area").on('tap', '.table-span-cp', function () {
		var postdata = {
			uid: uid,
			id: this.id
		};
		var me = this;
		plus.nativeUI.showWaiting("出票中...");
		mui.post(appurl + 'BuyApi/echoTrainl', postdata, function (res) {
			plus.nativeUI.closeWaiting();
			mui.alert(res.msg);
			
			if (res && res.error == 1) {
				//me.parentNode.removeChild(me);
				//var el = document.querySelector("#" + me.id);
				//el.classList.remove('table-span-go');
				//el.classList.addClass('table-span-co');
				me.setAttribute('class', 'table-span-co');
				me.innerHTML = '交易完成';
			}
		});
	});
	//console.log(mui.os.IS_IOS);
	setTimeout(function () {
		if (mui.os.ios) {
			document.getElementById('pullrefresh').style.marginTop = '50px';
		}
		mui('#pullrefresh').pullRefresh().pullupLoading();
	}, 1000);
});